home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / cslib15b.zip / DEMO / MENU / CSMENDEM.CPP next >
C/C++ Source or Header  |  1994-12-20  |  9KB  |  332 lines

  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "conio.h"
  4. #include "string.h"
  5. #include "cskeys.h"
  6. #include "csmenu.h"
  7.  
  8.  
  9.  
  10. /***********************************************************************
  11.  
  12.                                        CSA Library, Release 1.5.b 
  13.  
  14.  
  15.                The CSA Library.
  16.            A demonstration of the MENU class.
  17.  
  18.                                           Copyright(c) 1994 
  19.                                           Combis 
  20.                                           The Netherlands   
  21. ***********************************************************************/
  22.  
  23.  
  24.  
  25. void main(void)
  26. {
  27.  
  28.  
  29.   int choice;
  30.   int rc;
  31.  
  32. //////////////////////////// Declare all the (sub) menu's  //////////////
  33.  
  34.  MENU m1,m2,m3,m4,m5,m6,m7;
  35.  
  36.  
  37. /////////////////////////// Define the options for menu 1  //////////////
  38.  
  39.  
  40.  m1.add_option("   ~File  ",     ALT_F );
  41.  m1.add_option("   ~Edit  ",     ALT_E );
  42.  m1.add_option("   ~Printen  ",  ALT_P );
  43.  m1.add_option("   ~Database  ", ALT_D );
  44.  m1.add_option("   ~Utilities  ",ALT_U );
  45.  m1.add_option("   ~Setup  ",    ALT_S );
  46.  
  47.  
  48. /////////////////////////// Define the options for menu 2  //////////////
  49.  
  50.  m2.add_option("  ~Load      F3 "  ,F3);
  51.  m2.add_option("  ~Delete    "     ,F4);
  52.  m2.add_option("  ~Save      F2 "  ,F2);
  53.  m2.add_option("  ~Re-Start  "     ,F9);
  54.  m2.add_option("  ~Exit   ALT_X "  ,ALT_X );
  55.  
  56.  
  57. ////////////////////////// Define the options for menu 3  ///////////////
  58.  
  59.  
  60.  m3.add_option(" Free Memory ALT_M ",ALT_M );
  61.  m3.add_option(" Removing under scores ",501 );
  62.  
  63. ////////////////////////// Define the options for menu 4  ///////////////
  64.  
  65.  
  66.  m4.add_option(" Directories ",502 );
  67.  m4.add_option(" Colors "     ,503 );
  68.  m4.add_option(" Save Setup"  ,504 );
  69.  
  70. ////////////////////////// Define the options for menu 5  ///////////////
  71.  
  72.  
  73.  m5.add_option(" ~References  "       , 505 );
  74.  m5.add_option(" Reference ~Numbers >", 506 );
  75.  m5.add_option(" ~Maintenance "       ,507 );
  76.  
  77. ////////////////////////// Define the options for menu 6  ///////////////
  78.  
  79.  
  80.  m6.add_option(" ~Searching ALT_C ",ALT_C );
  81.  m6.add_option(" s~Et "            ,508 );
  82.  
  83. ////////////////////////// Define the options for menu 7 ////////////////
  84.  
  85.  
  86.  m7.add_option(" P~ages " , 509 );
  87.  m7.add_option(" P~rinten ",510 );
  88.  
  89. ///////////////// Make menu 1 'special' (main menu) ////////////////////
  90.  
  91.  
  92.   m1.type(MENU_HOR);             // Display options horizontally
  93.   m1.hold(MENU_HOLD);             // Make it 'always visible'
  94.   m1.border(BORDER_NONE);         // No border
  95.   m1.width(80);              // Set the width to the full screen
  96.  
  97.  
  98. //////////////////////////// Define the colors //////////////////////////
  99.  
  100.  
  101.   int bor_col;
  102.   int scr_col;
  103.   int opt_col;
  104.   int key_col;
  105.  
  106.  
  107.   if(is_color())
  108.   {
  109.     bor_col=make_color(WHITE,CYAN);
  110.     scr_col=make_color(WHITE,CYAN);
  111.     opt_col=make_color(WHITE,RED);
  112.     key_col=make_color(YELLOW,CYAN);
  113.   }
  114.   else
  115.   {
  116.     bor_col=make_color(LIGHTGRAY,BLACK);
  117.     scr_col=bor_col;
  118.     opt_col=make_color(BLACK,WHITE);
  119.     key_col=make_color(WHITE,BLACK);
  120.   }
  121.  
  122.  
  123. /////////////////////////////// Set the colors of each (Sub) menu /////////
  124.  
  125. //  m1.color(bor_col,make_color(YELLOW,RED),key_col,key_col);
  126.  
  127.   m1.color(bor_col,scr_col,opt_col,key_col);
  128.   m2.color(bor_col,scr_col,opt_col,key_col);
  129.   m3.color(bor_col,scr_col,opt_col,key_col);
  130.   m4.color(bor_col,scr_col,opt_col,key_col);
  131.   m5.color(bor_col,scr_col,opt_col,key_col);
  132.   m6.color(bor_col,scr_col,opt_col,key_col);
  133.   m7.color(bor_col,scr_col,opt_col,key_col);
  134.  
  135. ///////////////////////// Set the postions of the menu's ////////////////////
  136.  
  137.   m1.coord(1,1);
  138.   m2.coord(2,1);
  139.   m3.coord(2,40);
  140.   m4.coord(2,53);
  141.   m5.coord(2,28);
  142.   m6.coord(4,36);
  143.   m7.coord(1,1);
  144.   m7.relative_pos(TO_CURSOR);    // You can also define the position relative
  145.                 // to the cursor.
  146.  
  147. ////////////// Create the entire menu by connecting the sub-menu's //////////
  148.  
  149.   m1.connect(1,m2);
  150.   m1.connect(3,m7);
  151.   m1.connect(5,m3);
  152.   m1.connect(6,m4);
  153.   m1.connect(4,m5);
  154.   m5.connect(2,m6);
  155.  
  156.  
  157. ///////////////////  Start the demo   ////////////////////////////////
  158.  
  159.  
  160.  WINDOW bckgrnd;
  161.  bckgrnd.border(BORDER_NONE);
  162.  bckgrnd.activate();
  163.  
  164.  clrscr();
  165.  
  166.  
  167.  WINDOW hello;
  168.  
  169.  
  170.  hello.head(" Hello ");
  171.  hello.set_dim(-1,-1,22,60);
  172.  
  173.  hello.activate();
  174.  
  175.  cprintf("\n\r              Welcome to the CSMENU demo. ");
  176.  cprintf("\n\r                                          ");
  177.  cprintf("\n\r                                          ");
  178.  cprintf("\n\r    This demo is intended to give you     ");
  179.  cprintf("\n\r    a brief look at the possibilities     ");
  180.  cprintf("\n\r    of the MENU class.                    ");
  181.  cprintf("\n\r                                          ");
  182.  cprintf("\n\r    The demo consists of two parts:       ");
  183.  cprintf("\n\r                                          ");
  184.  cprintf("\n\r    a) A simple straightforward menu      ");
  185.  cprintf("\n\r       which let you browse through       ");
  186.  cprintf("\n\r       its options.                       ");
  187.  cprintf("\n\r                                          ");
  188.  cprintf("\n\r    b) An application style menu which    ");
  189.  cprintf("\n\r       let you choose an option directly  ");
  190.  cprintf("\n\r       by hitting a predefined key,       ");
  191.  cprintf("\n\r       or by browsing the menus.          ");
  192.  cprintf("\n\r                                          ");
  193.  cprintf("\n\r              Hit a key to start.         ");
  194.  
  195.  
  196.  
  197.  cskey();
  198.  
  199. ////////////////////////////////// Demo 1 ////////////////////////////
  200.  
  201.  hello.clear();
  202.  hello.head("");
  203.  hello.set_dim(18,10,6,60);
  204.  hello.adjust();
  205.  
  206.  cprintf("\n\r    - Use cursor keys to manoeuvre.       ");
  207.  cprintf("\n\r    - Hit ENTER to make a choice.         ");
  208.  cprintf("\n\r    - Leave by selecting 'Exit' from      ");
  209.  cprintf("\n\r      the menu.                           ");
  210.  
  211.  win_default();
  212.  
  213.  
  214.   do
  215.   {
  216.     m1.choose(choice);
  217.     gotoxy(10,14);
  218.     cprintf("\n\r Return Value: %d ",choice);
  219.   } while(choice!=ALT_X);
  220.  
  221.  m1.standby();
  222.  
  223.  clrscr();
  224.  
  225.  hello.head(" Last Demo ");
  226.  hello.set_dim(-1,-1,20,54);
  227.  hello.adjust();
  228.  hello.clear();
  229.  
  230.  cprintf("\n\r            The second & last demo.       ");
  231.  cprintf("\n\r                                          ");
  232.  cprintf("\n\r    In many applications you wish to provide   ");
  233.  cprintf("\n\r    the user with two ways to select an option:");
  234.  cprintf("\n\r      1) Directly hit a function-key.     ");
  235.  cprintf("\n\r      2) Browse the menu.                 ");
  236.  cprintf("\n\r                                          ");
  237.  cprintf("\n\r    In this example there are three       ");
  238.  cprintf("\n\r    options which work in that way:       ");
  239.  cprintf("\n\r    'load' = F3                           ");
  240.  cprintf("\n\r    'Save' = F2                           ");
  241.  cprintf("\n\r    'Reference ..' = ALT_C                ");
  242.  cprintf("\n\r                                          ");
  243.  cprintf("\n\r    Leave the demo by ALT_X.              ");
  244.  cprintf("\n\r                                          ");
  245.  cprintf("\n\r              Hit a key to start.         ");
  246.  
  247.  
  248.  cskey();
  249.  
  250.  
  251.   hello.head("");
  252.   hello.set_dim(17,-1,7,62);
  253.   hello.adjust();
  254.   hello.clear();
  255.  
  256.   cprintf("     F2:    Save \n\r");
  257.   cprintf("     F3:    Load \n\r");
  258.   cprintf("     ALT_C: Reference Number \n\r");
  259.   cprintf("     ESC:   Browse Menu \n\r");
  260.   cprintf("     ALT_X: Exit");
  261.  
  262.   win_default();
  263.  
  264.  
  265.   int key;
  266.   char regel[200];
  267.  
  268.   do
  269.   {
  270.     m1.standby();       // Finally display something.
  271.                // In the loop because we use
  272.                // choose_hold();
  273.     gotoxy(10,10);
  274.     cprintf(" Make your choice:"); clreol();
  275.  
  276.     key=cskey();       // Read a key.
  277.                // ESC means browse through the menus.
  278.  
  279.     if(key==ESC) m1.choose_hold(key); // Browse through the menu.
  280.     else     m1.show(key);          // Display the option directly.
  281.     switch(key)
  282.     {
  283.       case F3:          // LOAD
  284.        // Both the menu's are now being
  285.        // displayed.
  286.        // The option 'load' is highlighted.
  287.        //
  288.         gotoxy(10,10);
  289.         cprintf(" Loading file...."); clreol();
  290.        waitkb(3000);
  291.        //
  292.        break;
  293.       case F2:          // SAVE
  294.        // some
  295.        // code to
  296.        // save.
  297.        gotoxy(10,10);
  298.        cprintf(" Saving file......"); clreol();
  299.        waitkb(3000);
  300.        break;
  301.       case ALT_C:     // Reference Number
  302.        gotoxy(10,10);
  303.        cprintf(" Search for reference number......");
  304.        clreol();
  305.        waitkb(3000);
  306.        break;
  307.     }
  308.  
  309.   } while (key!=ALT_X);  // Use ALT_X to terminate demo.
  310.  
  311.  
  312.  
  313.   hello.set_dim(-1,-1,10,46);
  314.   hello.head(" The End ");
  315.   hello.adjust();
  316.   hello.clear();
  317.  
  318.   cprintf("\n\n\r   Thank you for watching ");
  319.   cprintf("\n\r   this demo.               ");
  320.   cprintf("\n\r");
  321.   cprintf("\n\r         Have a nice day.   ");
  322.  
  323.   waitkb(6000);
  324.   m1.remove();
  325.  
  326.   empty_kb();
  327.  
  328.  
  329.  
  330.  
  331. }
  332.